const DEBUG = false;
const DOC_BASE_URL = 'http://weex.apache.org/cn/references';

function getQueryParam(urlStr, paramName) {
  if (urlStr) {
    urlStr = urlStr.substr(urlStr.indexOf('?') + 1, urlStr.length);
    let reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)");
    var r = urlStr.match(reg);
    if (r != null) return unescape(r[2]);
  }
  return null;
}

function getBaseUrl() {
  if (DEBUG) {
    return 'http://192.168.78.48:8080';
  }
  return 'https://gitee.com/yubo725/WeexHandbook/raw/master';
}

function getDocAbsoluteUrl(docUrl) {
  return getBaseUrl() + '/dist/example/web_page.js?url=' + DOC_BASE_URL + docUrl;
}

function getDocDetailUrl(bundleUrl) {
  let docUrl = getQueryParam(bundleUrl, 'doc');
  return getDocAbsoluteUrl(docUrl);
}

module.exports = {
  getQueryParam: getQueryParam,
  getBaseUrl: getBaseUrl,
  getDocDetailUrl: getDocDetailUrl,
  getDocAbsoluteUrl: getDocAbsoluteUrl
}
